import requests
from bs4 import BeautifulSoup
import os
# import time


base = r'https://www.ndrc.gov.cn/xxgk/zcfb/fzggwl/'


def generate_url(i):
    if i == 0:
        return base + r'index.html?code=&state=123'
    else:
        return base + f'index_{i}.html?code=&state=123'


def parse_page(page):
    soup = BeautifulSoup(page, features='lxml')
    ulist = soup.select('ul.u-list > li')
    for li in ulist:
        if not li.has_attr('class'):
            print(li.span.text, li.a['title'])
            print(os.path.join(base, li.a['href']))


if __name__ == '__main__':
    for i in range(9):
        url = generate_url(i)
        page = requests.get(url)
        parse_page(page.content.decode('utf-8'))
        # time.sleep(2)
